import java.io.*;
import java.util.ArrayList;

public class java02 {
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("sort.txt");
        BufferedReader read = new BufferedReader(new InputStreamReader(fis));
        String line;
        ArrayList<String> str = new ArrayList<>();

        while ((line = read.readLine())!= null) {
            str.add(line);
        }

        str.sort(String::compareTo);
        FileWriter fos=new FileWriter("sort.txt");
        BufferedWriter write = new BufferedWriter(fos);

        for (int i = 0; i < str.size(); i++) {
            write.write(str.get(i));
            write.newLine(); // 增加换行，使每行数据独立
        }

        write.close();
        read.close();
    }
}
